package cn.jsj.cxsys.dao;

import cn.jsj.cxsys.dao.dynamicSQL.*;
import java.util.*;
import cn.jsj.cxsys.pojo.*;
import org.apache.ibatis.annotations.*;

public interface LabFunction
{
    @Results(id = "toUpdateInformation", value = { @Result(id = true, property = "ID", column = "ID"), @Result(property = "version", column = "version"), @Result(property = "updateDatatime", column = "show_time"), @Result(property = "description", column = "description", typeHandler = BlobToStringHandler.class) })
    @Select({ "select * from tb_application where ID=(select max(ID) from tb_application) limit 1" })
    UpdateInformation getLastUpdate();

    @Insert({ "insert into tb_application (version,show_time,description) values (#{version},#{updateDatatime},#{description})" })
    int showNewVersion(final UpdateInformation updateInformation);

    @Insert({ "insert into tb_lab (lab_name,lab_num,description,lader_id) values (#{labName},#{labNum},#{description},(select user_id from tb_user where lader=1 and tele_number=#{laderTeleNumber}))" })
    int insertOneLab(final Lab lab);

    @Results(id = "toLab", value = { @Result(id = true, property = "labID", column = "lab_id"), @Result(property = "labName", column = "lab_name"), @Result(property = "labNum", column = "lab_num"), @Result(property = "description", column = "description"), @Result(property = "laderName", column = "name"), @Result(property = "laderTeleNumber", column = "tele_number"), @Result(property = "StudentNumber", column = "stu_count") })
    @Select({ "select * from vi_lab where tele_number=#{laderTeleNumber} limit 1" })
    List<Lab> getLabOfTeacher(final String laderTeleNumber);

    @ResultMap({ "toLab" })
    @Select({ "select * from vi_lab" })
    List<Lab> getLabs();

    @ResultMap({ "toLab" })
    @Select({ "select * from vi_lab where lab_id=#{labID} limit 1" })
    Lab getLabByID(final int labID);

    @ResultMap({ "toLab" })
    @Select({ "select * from vi_lab where lab_num=#{labNum} limit 1" })
    Lab getLabByLabNum(final String labNum);

    @Results(id = "toUser", value = { @Result(id = true, property = "userID", column = "user_id"), @Result(property = "teleNumber", column = "tele_number"), @Result(property = "className", column = "class_name"), @Result(property = "name", column = "name"), @Result(property = "account", column = "account"), @Result(property = "password", column = "password") })
    @Select({ "select * from vi_user where user_id=(select lader_id from tb_lab where lab_id=#{labID}) limit 1" })
    User getLaderOfLabByID(final int labID);

    @Update({ "update tb_lab set stu_count=stu_count+1 where lab_id=#{labID} limit 1" })
    int labPeopleAddOne(final int labID);

    @Update({ "update tb_lab set stu_count=stu_count-1 where lab_id=#{labID} and stu_count>0 limit 1" })
    int labPeopleDecline(final int labID);

    @Update({ "update tb_lab set lab_name = #{labNewName} where lab_id = #{labID} limit 1" })
    int resetLabName(@Param("labID") final int labID, @Param("labNewName") final String labNewName);

    @Select({ "select count(*) from tb_lab where lab_id=#{labID} and lader_id=#{teacherID}" })
    int judgeTeacherIsTheLaderOfLab(final int teacherID, final int labID);

    @ResultMap({ "toUser" })
    @Select({ "select * from vi_user where user_id in (select user_id from tb_record where lab_id=#{labID} and out_time is null)" })
    List<User> getUserListOfLabThisTime(@Param("labID") final int labID);

    @Update({ "update tb_lab set description=#{str} where lab_id=#{labID} limit 1" })
    int changeDescriptionOfLab(@Param("labID") final int labID, @Param("str") final String str);
}
